//package com.plian.system.controller.hr.abroad;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.FileTools;
//import com.plian.Tools.Func;
//import com.plian.Tools.StringPool;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.common.status.CustomCode;
//import com.plian.system.config.Resubmit;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.dto.hr.abroad.AbroadPersonalDTO;
//import com.plian.system.entity.hr.abroad.AbroadPersonal;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.search.TokenSearch;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.hr.abroad.IAbroadPersonalService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.hr.abroad.AbroadPersonalVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.wrapper.hr.abroad.AbroadPersonalWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 因私出国（境）管理 控制器
// *
// * @author gangan
// * @since 2019-12-10
// */
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/abroadpersonal")
//public class AbroadPersonalController extends BaseController {
//
//	private IAbroadPersonalService abroadPersonalService;
//
//	private FormWorkflowService formWorkflowService;
//
//    private IFormCodeService formCodeService;
//
//    private AbroadPersonalWrapper abroadPersonalWrapper;
//
//	/**
//    * 详情
//    */
//	@PostMapping("/detail")
//	public R<AbroadPersonalVO> detail(@Valid @RequestBody AbroadPersonal abroadPersonal) {
//        AbroadPersonal detail = abroadPersonalService.getOne(Condition.getQueryWrapper(abroadPersonal));
//        AbroadPersonalVO abroadDeclarationVO = abroadPersonalWrapper.entityToVO(detail);
//        return R.data(abroadDeclarationVO);
//	}
//
//	/**
//	* 分页 因私出国（境）管理
//	*/
//	@PostMapping("/list")
//	public ListResult<AbroadPersonalVO> list(@Valid @RequestBody Query query) {
//		if(query.getAscs()==null&&query.getDescs()==null){
//            query.setDescs("create_time");
//		}
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<AbroadPersonal> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new AbroadPersonal()), entityList
//        );
//        TokenSearch<AbroadPersonal> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//		IPage<AbroadPersonal> pages = abroadPersonalService.page(Condition.getPage(query), queryWrapper);
//        List<AbroadPersonalVO> abroadPersonalVOS = abroadPersonalWrapper.entityToVO(pages.getRecords());
//        ListResult<AbroadPersonalVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(abroadPersonalVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//	}
//
//
//
//	/**
//	* 新增或修改 因私出国（境）管理
//	*/
//	@PostMapping("/submit")
//    @Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody AbroadPersonal abroadPersonal) {
//        if (abroadPersonal.getStatus() != null &&
//                (abroadPersonal.getStatus() != FormStatusConstant.UNREVIEWED && abroadPersonal.getStatus() != FormStatusConstant.STASH)) {
//            return new R(CustomCode.builder().message("当前单据不可编辑").code(1999).success(false).build());
//        }
//        if (abroadPersonal.getStatus() == null){
//            abroadPersonal.setStatus(FormStatusConstant.UNREVIEWED);
//        }
//
//		if(abroadPersonal.getId()==null){
//			abroadPersonal.setVersion("1");
//            abroadPersonal.setCode(formCodeService.getCode(FormTypeConstant.HR_ABROAD_PERSONAL_FORM));
//            abroadPersonal.setFormType(String.valueOf(FormTypeConstant.HR_ABROAD_PERSONAL_FORM));
//		}
//
//        boolean result = abroadPersonalService.saveOrUpdate(abroadPersonal);
//        HashMap<String, Object> processVariable = new HashMap<>();
//        formWorkflowService.startProcessAndSimulate(String.valueOf(abroadPersonal.getId()),abroadPersonal.getFormType(),processVariable);
//
//        return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//
//	/**
//	* 删除 因私出国（境）管理
//	*/
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//        List<String> ids = (List<String>)pd.get("ids");
//		return abroadPersonalService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//                ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	@PostMapping("/report")
//	public ObjResult reportTable(@Valid @RequestBody AbroadPersonalDTO abroadPersonalDTO) {
//        ObjResult objResult;
//        try {
//            ReportReturnVO reportReturnVO = abroadPersonalService.report(abroadPersonalDTO);
//            objResult = new ObjResult(CommonCode.SUCCESS);
//            if (Optional.ofNullable(reportReturnVO).isPresent()){
//                PageData pd = new PageData();
//                pd.put("grids", reportReturnVO.getGrids());
//                objResult.setPageData(pd);
//            }
//        }catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            objResult = new ObjResult(CommonCode.ERROR);
//            return objResult;
//        }
//
//        return objResult;
//	}
//
//	/**
//	 * 打印
//	 */
//	@GetMapping("/buildpdf/{id}")
//	public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) {
//		return FileTools.exportPdf(abroadPersonalService.createReceptFile(id));
//	}
//}
